//
//  DKAuthScuessCell.m
//  DanKU
//
//  Created by 吴斌 on 2023/11/5.
//

#import "DKAuthScuessCell.h"

static NSString * DKAuthScuessCellId = @"DKAuthScuessCellId";
@interface DKAuthScuessCell()
@property (nonatomic,strong) UIImageView *authScuessPhotoImgView;
@end
@implementation DKAuthScuessCell
+ (instancetype)authScuessCell:(UITableView *)tableView{
    DKAuthScuessCell * dk_AuthScuessCell = [tableView dequeueReusableCellWithIdentifier:DKAuthScuessCellId];
    if (!dk_AuthScuessCell) {
        dk_AuthScuessCell = [[DKAuthScuessCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DKAuthScuessCellId];
    }
    dk_AuthScuessCell.backgroundColor = [UIColor clearColor];
    dk_AuthScuessCell.selectionStyle = UITableViewCellSelectionStyleNone;
    dk_AuthScuessCell.accessoryType = UITableViewCellAccessoryNone;
    return dk_AuthScuessCell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    UIView *dk_AuthFaceView = [[UIView alloc] init];
    dk_AuthFaceView.backgroundColor = [UIColor whiteColor];
    dk_AuthFaceView.layer.cornerRadius = DK_IsWidthScale(10);
    dk_AuthFaceView.clipsToBounds = YES;
    [self.contentView addSubview:dk_AuthFaceView];
    [dk_AuthFaceView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.top.equalTo(@(DK_IsWidthScale(30)));
        make.height.equalTo(@(DK_IsWidthScale(260)));
    }];
    self.authScuessPhotoImgView = [[UIImageView alloc] init];
    self.authScuessPhotoImgView.contentMode = UIViewContentModeScaleAspectFill;
    self.authScuessPhotoImgView.userInteractionEnabled = YES;
    self.authScuessPhotoImgView.clipsToBounds = YES;
    [dk_AuthFaceView addSubview:self.authScuessPhotoImgView];
    [self.authScuessPhotoImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(dk_AuthFaceView);
        make.top.equalTo(@(DK_IsWidthScale(20)));
        make.bottom.equalTo(@(-DK_IsWidthScale(20)));
        make.width.equalTo(self.authScuessPhotoImgView.mas_height);
    }];
    
    UIImageView * dk_AuthFaceImgView = [[UIImageView alloc] init];
    dk_AuthFaceImgView.image = DK_GetImage(@"dk_AuthScuessIcon");
    dk_AuthFaceImgView.userInteractionEnabled = YES;
    [dk_AuthFaceView addSubview:dk_AuthFaceImgView];
    [dk_AuthFaceImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(@(DK_IsWidthScale(43)));
        make.width.equalTo(@(DK_IsWidthScale(80)));
        make.height.equalTo(@(DK_IsWidthScale(80)));
    }];
    UILabel * dk_AuthFaceLab = [[UILabel alloc] init];
    dk_AuthFaceLab.textColor = DK_Hex(@"#333333");
    dk_AuthFaceLab.font = DK_FONT_Medium(14);
    dk_AuthFaceLab.text = @"Congratulations on completing face recognition verification！";
    dk_AuthFaceLab.numberOfLines = 0;
    [dk_AuthFaceView addSubview:dk_AuthFaceLab];
    [dk_AuthFaceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(dk_AuthFaceImgView.mas_bottom).offset(DK_IsWidthScale(30));
        make.left.equalTo(@(DK_IsWidthScale(53)));
        make.right.equalTo(@(-DK_IsWidthScale(53)));
    }];
    UIButton * authPhotoBtn = [[UIButton alloc] init];
    [authPhotoBtn addTarget:self action:@selector(authPhoto) forControlEvents:UIControlEventTouchUpInside];
    [dk_AuthFaceView addSubview:authPhotoBtn];
    [authPhotoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.authScuessPhotoImgView);
    }];
    
    UIButton * dk_AuthFaceCertificationBtn = [[UIButton alloc] init];
    [dk_AuthFaceCertificationBtn setTitle:@"Next" forState:UIControlStateNormal];
    [dk_AuthFaceCertificationBtn setTitleColor:DK_Hex(@"#4566FF") forState:UIControlStateDisabled];
    [dk_AuthFaceCertificationBtn setTitleColor:DK_Hex(@"#FFFFFF") forState:UIControlStateNormal];
    dk_AuthFaceCertificationBtn.titleLabel.font = DK_FONT_Semibold(16);
    [dk_AuthFaceCertificationBtn setBackgroundImage:DK_GetImage(@"dk_registerNextSelectBg") forState:UIControlStateNormal];
    [dk_AuthFaceCertificationBtn addTarget:self action:@selector(authFaceCertification) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:dk_AuthFaceCertificationBtn];
    [dk_AuthFaceCertificationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.top.equalTo(dk_AuthFaceView.mas_bottom).offset(DK_IsWidthScale(52));
        make.height.equalTo(@(DK_IsWidthScale(50)));
    }];
    UIButton * dk_AgreementBtn = [[UIButton alloc] init];
    [dk_AgreementBtn setTitle:@"《Privacy Agreement》" forState:UIControlStateNormal];
    [dk_AgreementBtn setTitleColor:DK_Hex(@"#CCCCCC") forState:UIControlStateNormal];
    dk_AgreementBtn.titleLabel.font = DK_FONT_Regular(12);
    [dk_AgreementBtn addTarget:self action:@selector(CheckAgreement) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:dk_AgreementBtn];
    [dk_AgreementBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(dk_AuthFaceCertificationBtn.mas_bottom).offset(DK_IsWidthScale(20));
        make.height.equalTo(@(DK_IsWidthScale(17)));
    }];
}
-(void)setDk_AuthLiveBase64Mdl:(DKAuthLiveBase64Model *)dk_AuthLiveBase64Mdl{
    _dk_AuthLiveBase64Mdl = dk_AuthLiveBase64Mdl;
    if(_dk_AuthLiveBase64Mdl){
        self.authScuessPhotoImgView.image = [NSString imageWithBase64String:_dk_AuthLiveBase64Mdl.url];
        
    }
}
- (void)authFaceCertification{
    if(_dk_AuthLiveBase64Mdl){
        [DKPublicHttp apiUserBrhavRecordForAPI:@{} withPageName:DK_VerifyLiveness withAction:DK_ActionClick complete:^{
                
        } fail:^{
                
        }];
        
        NSMutableDictionary *userInfoDataDic = [[NSMutableDictionary alloc] init];
        [userInfoDataDic setObject:_dk_AuthLiveBase64Mdl.photoName forKey:@"liveImg"];
        [userInfoDataDic setObject:_dk_AuthLiveBase64Mdl.livenessId forKey:@"livenessId"];
        NSMutableDictionary *userInfoDic = [[NSMutableDictionary alloc] init];
        [userInfoDic setObject:userInfoDataDic forKey:@"data"];
        [userInfoDic setObject:@"LIVENESS_INFO" forKey:@"step"];
        [DKPublicHttp apiSaveUserInfoForAPI:userInfoDic complete:^{//保存用户信息
            if(self.StartCardAuthBlock){
                self.StartCardAuthBlock();
            }
            [DKPublicHttp apiUserBrhavRecordForAPI:@{} withPageName:DK_VerifyLiveness withAction:DK_ActionSave complete:^{
                    
            } fail:^{
                    
            }];
        }fail:^{
            
        }];
    }
}
- (void)authPhoto{
    if(self.AuthPhotoBlock){
        self.AuthPhotoBlock();
    }
}
- (void)CheckAgreement{
    if(self.CheckPrivacyAgreementBlock){
        self.CheckPrivacyAgreementBlock();
    }
}
@end
